module port2RamDequeueCrossBar (
    input wire clk,
    input wire rst,
    input wire [15:0] dequeue_vld_port,                 //出栈使能
    input wire [5:0] dequeue_priority_port [0:15],
    input wire [7:0] is_last_head_port [0:15],          //判断是否为此队列的最后一个元素
    input wire [15:0] dequeue_head_old_port [0:15],     //出队的旧队头
    output reg [31:0] dequeue_vld_ram,
    output reg [7:0] is_last_head_ram [0:31],
    output reg  [9:0] dequeue_head_old_ram [0:31]
);
    wire [31:0] dequeue_vld_port1;
    wire [31:0] dequeue_vld_port2;
    wire [31:0] dequeue_vld_port3;
    wire [31:0] dequeue_vld_port4;
    wire [31:0] dequeue_vld_port5;
    wire [31:0] dequeue_vld_port6;
    wire [31:0] dequeue_vld_port7;
    wire [31:0] dequeue_vld_port8;
    wire [31:0] dequeue_vld_port9;
    wire [31:0] dequeue_vld_port10;
    wire [31:0] dequeue_vld_port11;
    wire [31:0] dequeue_vld_port12;
    wire [31:0] dequeue_vld_port13;
    wire [31:0] dequeue_vld_port14;
    wire [31:0] dequeue_vld_port15;
    wire [31:0] dequeue_vld_port16;
    wire [7:0] is_last_head_port_port1 [0:31];
    wire [7:0] is_last_head_port_port2 [0:31];
    wire [7:0] is_last_head_port_port3 [0:31];
    wire [7:0] is_last_head_port_port4 [0:31];
    wire [7:0] is_last_head_port_port5 [0:31];
    wire [7:0] is_last_head_port_port6 [0:31];
    wire [7:0] is_last_head_port_port7 [0:31];
    wire [7:0] is_last_head_port_port8 [0:31];
    wire [7:0] is_last_head_port_port9 [0:31];
    wire [7:0] is_last_head_port_port10 [0:31];
    wire [7:0] is_last_head_port_port11 [0:31];
    wire [7:0] is_last_head_port_port12 [0:31];
    wire [7:0] is_last_head_port_port13 [0:31];
    wire [7:0] is_last_head_port_port14 [0:31];
    wire [7:0] is_last_head_port_port15 [0:31];
    wire [7:0] is_last_head_port_port16 [0:31];
    wire [9:0] dequeue_head_old_port1 [0:31];
    wire [9:0] dequeue_head_old_port2 [0:31];
    wire [9:0] dequeue_head_old_port3 [0:31];
    wire [9:0] dequeue_head_old_port4 [0:31];
    wire [9:0] dequeue_head_old_port5 [0:31];
    wire [9:0] dequeue_head_old_port6 [0:31];
    wire [9:0] dequeue_head_old_port7 [0:31];
    wire [9:0] dequeue_head_old_port8 [0:31];
    wire [9:0] dequeue_head_old_port9 [0:31];
    wire [9:0] dequeue_head_old_port10 [0:31];
    wire [9:0] dequeue_head_old_port11 [0:31];
    wire [9:0] dequeue_head_old_port12 [0:31];
    wire [9:0] dequeue_head_old_port13 [0:31];
    wire [9:0] dequeue_head_old_port14 [0:31];
    wire [9:0] dequeue_head_old_port15 [0:31];
    wire [9:0] dequeue_head_old_port16 [0:31];
    wire [5:0] dequeue_priority_port1 [0:31];
    wire [5:0] dequeue_priority_port2 [0:31];
    wire [5:0] dequeue_priority_port3 [0:31];
    wire [5:0] dequeue_priority_port4 [0:31];
    wire [5:0] dequeue_priority_port5 [0:31];
    wire [5:0] dequeue_priority_port6 [0:31];
    wire [5:0] dequeue_priority_port7 [0:31];
    wire [5:0] dequeue_priority_port8 [0:31];
    wire [5:0] dequeue_priority_port9 [0:31];
    wire [5:0] dequeue_priority_port10 [0:31];
    wire [5:0] dequeue_priority_port11 [0:31];
    wire [5:0] dequeue_priority_port12 [0:31];
    wire [5:0] dequeue_priority_port13 [0:31];
    wire [5:0] dequeue_priority_port14 [0:31];
    wire [5:0] dequeue_priority_port15 [0:31];
    wire [5:0] dequeue_priority_port16 [0:31];

    dequeuePortDeMuxer32 part1Demux(.clk(clk), .rst(rst), 
                                    .dequeue_vld_in(dequeue_vld_port[0]), .is_last_head_in(is_last_head_port[0]), .dequeue_head_old_in(dequeue_head_old_port[0]), .dequeue_priority_in(dequeue_priority_port[0]),
                                    .dequeue_vld_out(dequeue_vld_port1), .is_last_head_out(is_last_head_port_port1), .dequeue_head_old_out(dequeue_head_old_port1), .dequeue_priority_out(dequeue_priority_port1));

    dequeuePortDeMuxer32 part2Demux(.clk(clk), .rst(rst), 
                                    .dequeue_vld_in(dequeue_vld_port[1]), .is_last_head_in(is_last_head_port[1]), .dequeue_head_old_in(dequeue_head_old_port[1]),  .dequeue_priority_in(dequeue_priority_port[1]),
                                    .dequeue_vld_out(dequeue_vld_port2), .is_last_head_out(is_last_head_port_port2), .dequeue_head_old_out(dequeue_head_old_port2), .dequeue_priority_out(dequeue_priority_port2));

    dequeuePortDeMuxer32 part3Demux(.clk(clk), .rst(rst), 
                                    .dequeue_vld_in(dequeue_vld_port[2]), .is_last_head_in(is_last_head_port[2]), .dequeue_head_old_in(dequeue_head_old_port[2]), .dequeue_priority_in(dequeue_priority_port[2]),
                                    .dequeue_vld_out(dequeue_vld_port3), .is_last_head_out(is_last_head_port_port3), .dequeue_head_old_out(dequeue_head_old_port3), .dequeue_priority_out(dequeue_priority_port3));

    dequeuePortDeMuxer32 part4Demux(.clk(clk), .rst(rst), 
                                    .dequeue_vld_in(dequeue_vld_port[3]), .is_last_head_in(is_last_head_port[3]), .dequeue_head_old_in(dequeue_head_old_port[3]), .dequeue_priority_in(dequeue_priority_port[3]), 
                                    .dequeue_vld_out(dequeue_vld_port4), .is_last_head_out(is_last_head_port_port4), .dequeue_head_old_out(dequeue_head_old_port4), .dequeue_priority_out(dequeue_priority_port4));
    
    dequeuePortDeMuxer32 part5Demux(.clk(clk), .rst(rst), 
                                    .dequeue_vld_in(dequeue_vld_port[4]), .is_last_head_in(is_last_head_port[4]), .dequeue_head_old_in(dequeue_head_old_port[4]), .dequeue_priority_in(dequeue_priority_port[4]), 
                                    .dequeue_vld_out(dequeue_vld_port5), .is_last_head_out(is_last_head_port_port5), .dequeue_head_old_out(dequeue_head_old_port5), .dequeue_priority_out(dequeue_priority_port5));

    dequeuePortDeMuxer32 part6Demux(.clk(clk), .rst(rst), 
                                    .dequeue_vld_in(dequeue_vld_port[5]), .is_last_head_in(is_last_head_port[5]), .dequeue_head_old_in(dequeue_head_old_port[5]), .dequeue_priority_in(dequeue_priority_port[5]),  
                                    .dequeue_vld_out(dequeue_vld_port6), .is_last_head_out(is_last_head_port_port6), .dequeue_head_old_out(dequeue_head_old_port6), .dequeue_priority_out(dequeue_priority_port6));

    dequeuePortDeMuxer32 part7Demux(.clk(clk), .rst(rst), 
                                    .dequeue_vld_in(dequeue_vld_port[6]), .is_last_head_in(is_last_head_port[6]), .dequeue_head_old_in(dequeue_head_old_port[6]), .dequeue_priority_in(dequeue_priority_port[6]),  
                                    .dequeue_vld_out(dequeue_vld_port7), .is_last_head_out(is_last_head_port_port7), .dequeue_head_old_out(dequeue_head_old_port7), .dequeue_priority_out(dequeue_priority_port7));

    dequeuePortDeMuxer32 part8Demux(.clk(clk), .rst(rst), 
                                    .dequeue_vld_in(dequeue_vld_port[7]), .is_last_head_in(is_last_head_port[7]), .dequeue_head_old_in(dequeue_head_old_port[7]), .dequeue_priority_in(dequeue_priority_port[7]), 
                                    .dequeue_vld_out(dequeue_vld_port8), .is_last_head_out(is_last_head_port_port8), .dequeue_head_old_out(dequeue_head_old_port8), .dequeue_priority_out(dequeue_priority_port8));

    dequeuePortDeMuxer32 part9Demux(.clk(clk), .rst(rst), 
                                    .dequeue_vld_in(dequeue_vld_port[8]), .is_last_head_in(is_last_head_port[8]), .dequeue_head_old_in(dequeue_head_old_port[8]), .dequeue_priority_in(dequeue_priority_port[8]), 
                                    .dequeue_vld_out(dequeue_vld_port9), .is_last_head_out(is_last_head_port_port9), .dequeue_head_old_out(dequeue_head_old_port9), .dequeue_priority_out(dequeue_priority_port9));

    dequeuePortDeMuxer32 part10Demux(.clk(clk), .rst(rst), 
                                    .dequeue_vld_in(dequeue_vld_port[9]), .is_last_head_in(is_last_head_port[9]), .dequeue_head_old_in(dequeue_head_old_port[9]), .dequeue_priority_in(dequeue_priority_port[9]),
                                    .dequeue_vld_out(dequeue_vld_port10), .is_last_head_out(is_last_head_port_port10), .dequeue_head_old_out(dequeue_head_old_port10), .dequeue_priority_out(dequeue_priority_port10));

    dequeuePortDeMuxer32 part11Demux(.clk(clk), .rst(rst), 
                                    .dequeue_vld_in(dequeue_vld_port[10]), .is_last_head_in(is_last_head_port[10]), .dequeue_head_old_in(dequeue_head_old_port[10]), .dequeue_priority_in(dequeue_priority_port[10]),
                                    .dequeue_vld_out(dequeue_vld_port11), .is_last_head_out(is_last_head_port_port11), .dequeue_head_old_out(dequeue_head_old_port11), .dequeue_priority_out(dequeue_priority_port11));

    dequeuePortDeMuxer32 part12Demux(.clk(clk), .rst(rst), 
                                    .dequeue_vld_in(dequeue_vld_port[11]), .is_last_head_in(is_last_head_port[11]), .dequeue_head_old_in(dequeue_head_old_port[11]), .dequeue_priority_in(dequeue_priority_port[11]),
                                    .dequeue_vld_out(dequeue_vld_port12), .is_last_head_out(is_last_head_port_port12), .dequeue_head_old_out(dequeue_head_old_port12), .dequeue_priority_out(dequeue_priority_port12));

    dequeuePortDeMuxer32 part13Demux(.clk(clk), .rst(rst), 
                                    .dequeue_vld_in(dequeue_vld_port[12]), .is_last_head_in(is_last_head_port[12]), .dequeue_head_old_in(dequeue_head_old_port[12]), .dequeue_priority_in(dequeue_priority_port[12]), 
                                    .dequeue_vld_out(dequeue_vld_port13), .is_last_head_out(is_last_head_port_port13), .dequeue_head_old_out(dequeue_head_old_port13), .dequeue_priority_out(dequeue_priority_port13));

    dequeuePortDeMuxer32 part14Demux(.clk(clk), .rst(rst), 
                                    .dequeue_vld_in(dequeue_vld_port[13]), .is_last_head_in(is_last_head_port[13]), .dequeue_head_old_in(dequeue_head_old_port[13]), .dequeue_priority_in(dequeue_priority_port[13]),
                                    .dequeue_vld_out(dequeue_vld_port14), .is_last_head_out(is_last_head_port_port14), .dequeue_head_old_out(dequeue_head_old_port14), .dequeue_priority_out(dequeue_priority_port14));


    dequeuePortDeMuxer32 part15Demux(.clk(clk), .rst(rst), 
                                    .dequeue_vld_in(dequeue_vld_port[14]), .is_last_head_in(is_last_head_port[14]), .dequeue_head_old_in(dequeue_head_old_port[14]), .dequeue_priority_in(dequeue_priority_port[14]),
                                    .dequeue_vld_out(dequeue_vld_port15), .is_last_head_out(is_last_head_port_port15), .dequeue_head_old_out(dequeue_head_old_port15), .dequeue_priority_out(dequeue_priority_port15));

    dequeuePortDeMuxer32 part16Demux(.clk(clk), .rst(rst), 
                                    .dequeue_vld_in(dequeue_vld_port[15]), .is_last_head_in(is_last_head_port[15]), .dequeue_head_old_in(dequeue_head_old_port[15]), .dequeue_priority_in(dequeue_priority_port[15]),
                                    .dequeue_vld_out(dequeue_vld_port16), .is_last_head_out(is_last_head_port_port16), .dequeue_head_old_out(dequeue_head_old_port16), .dequeue_priority_out(dequeue_priority_port16));

    genvar dmIndex;
    generate
        for (dmIndex=0; dmIndex<32; dmIndex=dmIndex+1) begin : dequeeuMuxer
            dequeueMuxer16 denqueue(.clk(clk), .rst(rst), 
                                    .dequeue_vld_1(dequeue_vld_port1[dmIndex]), .dequeue_vld_2(dequeue_vld_port2[dmIndex]), .dequeue_vld_3(dequeue_vld_port3[dmIndex]), .dequeue_vld_4(dequeue_vld_port4[dmIndex]), .dequeue_vld_5(dequeue_vld_port5[dmIndex]), .dequeue_vld_6(dequeue_vld_port6[dmIndex]), .dequeue_vld_7(dequeue_vld_port7[dmIndex]), .dequeue_vld_8(dequeue_vld_port8[dmIndex]), .dequeue_vld_9(dequeue_vld_port9[dmIndex]), .dequeue_vld_10(dequeue_vld_port10[dmIndex]), .dequeue_vld_11(dequeue_vld_port11[dmIndex]), .dequeue_vld_12(dequeue_vld_port12[dmIndex]), .dequeue_vld_13(dequeue_vld_port13[dmIndex]), .dequeue_vld_14(dequeue_vld_port14[dmIndex]), .dequeue_vld_15(dequeue_vld_port15[dmIndex]), .dequeue_vld_16(dequeue_vld_port16[dmIndex]), 
                                    .is_last_head_1(is_last_head_port_port1[dmIndex]), .is_last_head_2(is_last_head_port_port2[dmIndex]), .is_last_head_3(is_last_head_port_port3[dmIndex]), .is_last_head_4(is_last_head_port_port4[dmIndex]), .is_last_head_5(is_last_head_port_port5[dmIndex]), .is_last_head_6(is_last_head_port_port6[dmIndex]), .is_last_head_7(is_last_head_port_port7[dmIndex]), .is_last_head_8(is_last_head_port_port8[dmIndex]), .is_last_head_9(is_last_head_port_port9[dmIndex]), .is_last_head_10(is_last_head_port_port10[dmIndex]), .is_last_head_11(is_last_head_port_port11[dmIndex]), .is_last_head_12(is_last_head_port_port12[dmIndex]), .is_last_head_13(is_last_head_port_port13[dmIndex]), .is_last_head_14(is_last_head_port_port14[dmIndex]), .is_last_head_15(is_last_head_port_port15[dmIndex]), .is_last_head_16(is_last_head_port_port16[dmIndex]), 
                                    .dequeue_priority_1(dequeue_priority_port1[dmIndex]), .dequeue_priority_2(dequeue_priority_port2[dmIndex]), .dequeue_priority_3(dequeue_priority_port3[dmIndex]), .dequeue_priority_4(dequeue_priority_port4[dmIndex]), .dequeue_priority_5(dequeue_priority_port5[dmIndex]), .dequeue_priority_6(dequeue_priority_port6[dmIndex]), .dequeue_priority_7(dequeue_priority_port7[dmIndex]), .dequeue_priority_8(dequeue_priority_port8[dmIndex]), .dequeue_priority_9(dequeue_priority_port9[dmIndex]), .dequeue_priority_10(dequeue_priority_port10[dmIndex]), .dequeue_priority_11(dequeue_priority_port11[dmIndex]), .dequeue_priority_12(dequeue_priority_port12[dmIndex]), .dequeue_priority_13(dequeue_priority_port13[dmIndex]), .dequeue_priority_14(dequeue_priority_port14[dmIndex]), .dequeue_priority_15(dequeue_priority_port15[dmIndex]), .dequeue_priority_16(dequeue_priority_port16[dmIndex]), 
                                    .dequeue_head_old_1(dequeue_head_old_port1[dmIndex]), .dequeue_head_old_2(dequeue_head_old_port2[dmIndex]), .dequeue_head_old_3(dequeue_head_old_port3[dmIndex]), .dequeue_head_old_4(dequeue_head_old_port4[dmIndex]), .dequeue_head_old_5(dequeue_head_old_port5[dmIndex]), .dequeue_head_old_6(dequeue_head_old_port6[dmIndex]), .dequeue_head_old_7(dequeue_head_old_port7[dmIndex]), .dequeue_head_old_8(dequeue_head_old_port8[dmIndex]), .dequeue_head_old_9(dequeue_head_old_port9[dmIndex]), .dequeue_head_old_10(dequeue_head_old_port10[dmIndex]), .dequeue_head_old_11(dequeue_head_old_port11[dmIndex]), .dequeue_head_old_12(dequeue_head_old_port12[dmIndex]), .dequeue_head_old_13(dequeue_head_old_port13[dmIndex]), .dequeue_head_old_14(dequeue_head_old_port14[dmIndex]), .dequeue_head_old_15(dequeue_head_old_port15[dmIndex]), .dequeue_head_old_16(dequeue_head_old_port16[dmIndex]), 
                                    .dequeue_vld(dequeue_vld_ram[dmIndex]), .is_last_head(is_last_head_ram[dmIndex]), .dequeue_head_old(dequeue_head_old_ram[dmIndex]));
        end
    endgenerate
endmodule